package com.primefaces.www.dao;

import net.sf.ehcache.CacheManager;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public abstract class BaseDAO {

	private static final Logger logger = LoggerFactory
			.getLogger(BaseDAO.class);

	@Autowired
	private SessionFactory sessionFactory;

	@Autowired
	public CacheManager cacheManager;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public Session getCurrentSession(){
		Session session = null;//this.sessionFactory.getCurrentSession();
		if(session == null){
			session = this.sessionFactory.openSession();
		}
		return session;
	}
}
